package org.dromara.system.controller.device;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.system.domain.VariableAssociationParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.VariableAssociationParamVo;
import org.dromara.system.domain.bo.VariableAssociationParamBo;
import org.dromara.system.service.IVariableAssociationParamService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 变量参数关联
 *
 * @author Lion Li
 * @date 2024-10-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system")
public class VariableAssociationParamController extends BaseController {

    private final IVariableAssociationParamService variableAssociationParamService;

    /**
     * 查询变量参数关联列表
     */
    @SaCheckPermission("system:association:list")
    @GetMapping("/associationParam/list")
    public TableDataInfo<VariableAssociationParamVo> list(VariableAssociationParamBo bo, PageQuery pageQuery) {
        return variableAssociationParamService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取变量参数关联详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:association:list")
    @GetMapping("/associationParam/{id}")
    public R<VariableAssociationParamVo> getInfo(@NotNull(message = "主键不能为空")
                                                 @PathVariable Long id) {
        return R.ok(variableAssociationParamService.queryById(id));
    }

    /**
     * 新增变量参数关联
     */
    @SaCheckPermission("system:association:list")
    @Log(title = "变量参数关联", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/associationParam")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody VariableAssociationParamBo bo) {
        return toAjax(variableAssociationParamService.insertByBo(bo));
    }

    /**
     * 修改变量参数关联
     */
    @SaCheckPermission("system:association:list")
    @Log(title = "变量参数关联", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/associationParam/{id}")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody VariableAssociationParamBo bo, @PathVariable("id") Long id) {
        return toAjax(variableAssociationParamService.updateByBo(bo, id));
    }

    /**
     * 删除变量参数关联
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:association:list")
    @Log(title = "变量参数关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/associationParam/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(variableAssociationParamService.deleteWithValidByIds(List.of(ids), true));
    }


    @SaCheckPermission("system:association:list")
    @GetMapping("/getAssociationParam/{id}")
    public R<List<VariableAssociationParam>> getAssociationParam(@NotNull(message = "变量id不能为空")
                                                                 @PathVariable Long id) {
        return R.ok(variableAssociationParamService.getAssociationParam(id));
    }

}
